<?php

/**
 * dev actions.
 *
 * @package    essayLibrary
 * @subpackage dev
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class devActions extends sfGraduaActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
    public function executeCreateAction($request)
    {
        $moduleName = $this->getRequestParameter('moduleName');
        $actionName = $this->getRequestParameter('actionName');

        $filepath = '../apps/frontend/modules/' . $moduleName . '/actions/actions.class.php';

        sfLoader::loadHelpers(array('Partial','Php2Js'));
        $methodCode = get_partial(
      'dev/basicAction',
            array(
        'actionName' => $actionName,
            )
        );

        $fileCode = file_get_contents($filepath);
        $position = strrpos($fileCode,'}');
        $inicio = substr($fileCode,0,$position);
        $fim    = substr($fileCode,$position);
        $fileCode = $inicio.$methodCode."\n".$fim;
        file_put_contents($filepath, $fileCode);
        $this->openOnIde($filepath);

        $jsCall = JsCall::build();
        $this->getResponse()->setJsCall($jsCall);
        $jsCall->showFeedback('Método criado: '.$moduleName.'::'.$actionName);
        return sfView::NONE;
    }

    public function executeRia($request) {
        $this->projects = ProjectsService::getAll();
        sfLoader::loadHelpers(array('Partial','Php2Js'));
        $this->viewTpl  = partial2Js('dev/simpleView.jstpl',array(),true);
        $this->formTpl  = partial2Js('dev/form.jstpl',array(),true);
        $this->editDecorator   = partial2Js('dev/editDecorator.jstpl',array(),true);
        $this->insertDecorator = partial2Js('globalPartials/insertDecorator.jstpl',array(),true);
        $this->viewDecorator   = partial2Js('dev/viewDecorator.jstpl',array(),true);

        $this->tdListItemDecorator   = partial2Js('dev/tdListItemDecorator.jstpl',array(),true);
        $this->divListItemDecorator   = partial2Js('dev/divListItemDecorator.jstpl',array(),true);
        $this->listTpl   = partial2Js('dev/listTpl.jstpl',array(),true);
        $this->tableTpl   = partial2Js('dev/tableTpl.jstpl',array(),true);

        $this->setLayout('layoutTasks');
    }

}
